<script>
  let str = "北京你好北京好北京京"
  let obj = {}
  let maxCount = 0
  let maxKey = ""

  for (let val of str) {
    if (obj[val]) {
      obj[val] += 1
    } else {
      obj[val] = 1
    }
  }

  for (let key in obj) {
    if (obj[key] > maxCount) {
      maxCount = obj[key]
      maxKey = key
    }

  }

  console.log({char:maxKey,count:maxCount})
</script>